<template>
  <div
    id="sidebar"
    v-infinite-scroll="load"
    infinite-scroll-disabled="isLoadBusy"
    infinite-scroll-throttle-delay="1000"
    infinite-scroll-distance="10"
  >
    <div class="item">
      <div class="point" :class="{active:barIndex==0}"></div>
      <router-link to="/"><i class="el-icon-house" :class="{active:barIndex==0}"></i><span @click="barIndex = 0">首页</span></router-link>
    </div>
    <div class="split">我的音乐</div>
    <div class="item">
      <div class="point" :class="{active:barIndex==1}" ></div>
      <router-link to="/"><i class="el-icon-time" :class="{active:barIndex==1}"></i><span @click="barIndex = 1">最近播放</span></router-link>
    </div>
    <div class="item">
      <div class="point" :class="{active:barIndex==2}"></div>
      <router-link to="/"><i class="el-icon-star-off" :class="{active:barIndex==2}"></i><span @click="barIndex = 2">我的收藏</span></router-link>
    </div>
    <div class="split">
      <span>创建的歌单</span>
      <router-link to="" class="el-icon-caret-bottom"></router-link>
    </div>
    <div class="item">
      <div class="point"  :class="{active:barIndex==3}" ></div>
      <router-link :to="'/playlist/' + list[0].id"
        ><i class="iconfont icon-l-love" :class="{active:barIndex==3}" ></i
        ><span class="list-name" @click="barIndex = 3">我喜欢的音乐</span></router-link
      >
    </div>
    <div class="item" v-for="(item, index) in list.slice(1)" :key="item.id">
      <div class="point"  :class="{active:barIndex==index+4}"></div>
      <router-link :to="'/playlist/' + item.id"
        ><i class="iconfont icon-music-list" :class="{active:barIndex==index+4}"></i
        ><span class="list-name"  @click="barIndex = index+4">{{ item.name }}</span></router-link
      >
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "Sidebar",
  data() {
    return {
      list: [],
      isLoadBusy:false,
      barIndex:0
    };
  },
  computed: {
    ...mapState({
      userPlaylist: (store) => store.sidebar.userPlaylist,
    }),
  },
  watch: {
    userPlaylist(newValue) {
      this.list = newValue.playlist;
    },
  },
  methods:{
    // 无限加载
    load(){
      console.log('load')
    }
  },
  mounted() {
    // 判断是否有 uid
    let uid = localStorage.getItem("uid");
    if (uid != null) {
      this.$store.dispatch("userPlaylist", uid);
    }
  },
};
</script>

<style lang='less' scope>
#sidebar {
  height: 81vh;
  width: 180px;
  position: fixed;
  overflow-y: scroll;
  color: #fff;
  align-content: center;
  font-size: 14px;
  padding-right: 20px;

  .item {
    display: flex;
    margin-top: 15px;
    align-items: ceneter;
    .list-name {
      display: -webkit-box; /**对象作为伸缩盒子模型展示**/
      -webkit-box-orient: vertical; /**设置或检索伸缩盒子对象的子元素的排列方式**/
      -webkit-line-clamp: 1; /**显示的行数**/
      overflow: hidden; /**隐藏超出的内容**/
    }
    a {
      display: flex;
      align-items: center;
    }
    i {
      margin-right: 5px;
      font-size: 18px;
    }
    .point {
      width: 5px;
      height: 28px;
      margin-right: 10px;
      border-radius: 0 5px 5px 0;
    }
    .active {
      color: var(--themeColor1);
    }
    .active.point {
      background: var(--themeColor1);
    }
  }
  .split {
    display: flex;
    margin-top: 20px;
    margin-left: 25px;
    color: #999;
    font-size: 14px;
    align-items: center;
    a {
      margin-left: 5px;
      color: #999;
    }
  }
  .item:hover {
    a {
      color: var(--themeColor1);
    }
  }
}
</style>